﻿using PLCS.App.Shared.Extensions;
using PLCS.App.Shared.ViewModels;
using PLCS.Application.Contracts.ConfigApp.Dtos;
using PLCS.Client.IService.ConfigManager;
using PLCS.Domain.Shared.Enums;

using System.Threading.Tasks;

namespace PLCS.App.ConfigManager.ViewModels.Config;

internal class ConfigViewModel : NavigationPagedCurdViewModel<ConfigDto, ConfigEditDto, IConfigService>
{
    private string _name;

    public string Name
    {
        get { return _name; }
        set { SetProperty(ref _name, value); }
    }

    public ConfigViewModel(IConfigService service) : base(service)
    {
    }

    public override async Task GetPageData(int pageIndex)
    {
        try
        {
            UpdateLoading(true);
            var res = await _service.GetListBySearchAsync((pageIndex - 1) * PageSize, PageSize, Name);
            TotalCount = (int)res.TotalCount;
            SetPageCount();
            DataGridList = res.Items.ToObservable();
        }
        finally
        {
            UpdateLoading(false);
        }
    }
}